<?php
	$url = get_bloginfo('home')."/wp-admin/admin.php?page=tour-setting&action=tour-booked"; 
?>
<style>
.item-second a
{
	text-decoration:none;
}
.item-second a:hover
{
	text-decoration:underline;
}
</style>
<div id="index_page">
Page : 
<?php 
// xu ly xoa du lieu
if(isset($_GET['del']))
{
	$del = $_GET['del'];
	db_delete_order_tour($del);
	wp_redirect($url);
}

// xu ly phan trang
$total_book = db_select_all_data("orders");
$total_post = count($total_book);
$number_post_page = 40;
if(isset($_POST['set_number_post']))
{	
	$number_post_page = $_POST['set_number_post'];
	$_SESSION['set_number_post'] = $number_post_page;
}
else 
{
	if($_SESSION['set_number_post'] != null)
		$number_post_page = $_SESSION['set_number_post'];
}
	
if(!isset($_GET['p']))
{
	$start = 0;
	$end = $number_post_page;
}
else 
{
	$cp = $_GET['p'];
	$end = $number_post_page*$cp;
	$start = $end - $number_post_page;
}

$number_page = ceil($total_post/$number_post_page);
if($number_page>1)
{
	for($i=1;$i<=$number_page;$i++)
	{
		if($cp==$i)
		{
		?>
		<a href="<?php bloginfo('home');?>/wp-admin/admin.php?page=tour-setting&action=tour-booked&p=<?php echo $i;?>" style="color: red; font-weight: bold;"><?php echo $i;?></a> &nbsp;|&nbsp;
		<?php 	
		}
		else 
		{
		?>
		<a href="<?php bloginfo('home');?>/wp-admin/admin.php?page=tour-setting&action=tour-booked&p=<?php echo $i;?>"><?php echo $i;?></a> &nbsp;|&nbsp;
		<?php 	
		}
	}
}
?>
&nbsp;&nbsp;
&nbsp;&nbsp;
<form action="" method="post">
<select name="set_number_post" onchange="this.form.submit();">
	<option value="">-Set Number Post-</option>
	<option <?php if($_SESSION['set_number_post']==30) echo 'selected="selected"';?> value="30">30</option>
	<option <?php if($_SESSION['set_number_post']==40) echo 'selected="selected"';?> value="40">40</option>
	<option <?php if($_SESSION['set_number_post']==50) echo 'selected="selected"';?> value="50">50</option>
	<option <?php if($_SESSION['set_number_post']==60) echo 'selected="selected"';?> value="60">60</option>
	<option <?php if($_SESSION['set_number_post']==80) echo 'selected="selected"';?> value="80">80</option>
	<option <?php if($_SESSION['set_number_post']==100) echo 'selected="selected"';?> value="100">100</option>
	<option <?php if($_SESSION['set_number_post']==150) echo 'selected="selected"';?> value="150">150</option>	
</select>
</form>
<table>	
	<tr class="first-header">
		<td class="col1"> Book ID</td>
		<td class="col2"> Customer </td>
		<td class="col3"> Item </td>		
		<td class="col4"> Order Status</td>
		<td class="col4"> Payment Status</td>
		<td class="col4"> Method</td>
		<td class="col5"> Date</td>
		<td class="col6"> Actions </td>				
	</tr>
	<?php	
	$bookeds = db_select_all_data_limit("orders", $start, $number_post_page,1);
	if ($bookeds)
	{
		foreach ($bookeds as $value) 
		{
			$customerID = $value->customerID;
			$paymentID  = $value->paymentID;
			$datas = db_select_data_by_int("tours", "ID", $value->itemID);		
			$tourid		= $datas[0]->tourID;		
			$customer = db_table_get_id_by("customers", $customerID);
			$payment  = db_table_get_id_by("payments", $paymentID);
			
			//$tours	  = db_table_get_id_by("tours", $tourid);
			$new = db_get_new_image($value->ID);	
			//print_r($new);
		?>
		<tr class="item-second">
			<td class="col1"> <?php echo $value->ID; echo $new;?></td>
			<td class="col2"> <?php echo $customer[0]->customerName;?> </td>
			<td class="col3"><a target="_blank" href="<?php echo get_permalink($tourid);?>" title="<?php echo get_the_title($tourid);?>"> <?php echo db_shortDesc(get_the_title($tourid), 70);?> </a></td>
			<td class="col4"> <?php echo $value->orderStatus;?></td>
			<td class="col4"> <?php if($payment[0]->paymentStatus=="Completed" || $payment[0]->paymentStatus=="completed") echo '<span style="color:red;">'.$payment[0]->paymentStatus.'</span>'; else echo $payment[0]->paymentStatus;?></td>
			<td class="col4"> <?php echo $payment[0]->paymentMethod;?></td>
			<td class="col5"> <?php echo $value->date;?></td>
			<td class="col6">
				<a href="<?php echo $url;?>&view=<?php echo $value->ID;?>">View</a> |
				<a href="<?php echo $url;?>&del=<?php echo $value->ID;?>">Delete</a> 
			</td>				
		</tr>
		<?php 
		}
	} 
	?>
</table>
</div>